import { util } from '@/utils'

function initAppThemeMode() {
  let theme = util.Theme.getTheme()
  // 获取默认的模式： light 或 dark
  if (!theme) {
    const scheme = window.matchMedia('(prefers-color-scheme: dark)')
    theme = scheme.matches ? 'dark' : 'light'
    util.Theme.setTheme(theme)
  }

  const html = document.documentElement
  html.classList.remove('light', 'dark')
  html.classList.add(theme)
}

function initAppConfig() {
  // 设置参数信息
  const setting = util.Setting.getSetting()
  if (setting === null) {
    util.Setting.setSetting({
      city: '',
      weatherKey: '',
      weatherUrl: '',
      amapKey: '',
      amapSecret: '',
    })
  }
}

function initAppTitle() {
  document.title = util.Setting.AppName
}

function initApp() {
  initAppThemeMode()
  initAppConfig()
  initAppTitle()
}

export { initApp }
